﻿#pragma once
#include <memory>
#include "as_socket.h"
#include "time_value.h"
#include "as_awaiter.h"

namespace as {
	namespace net {


		class EpollWatch;
		class Channel;
		class Acceptor
		{
		public:
			typedef std::function<void(socket_fd, Address&)> NewConnectCb;
			Acceptor(std::shared_ptr<EpollWatch> &ep, const Address &addr);
			~Acceptor();
		public:
			int bind();
			int listen();
			void close();

			int HandleRead(TimeValue &tv);
		public:
			void SetNewConnCallback(NewConnectCb fun);

		private:
			Address local_;
			Socket socket_;
			std::weak_ptr<EpollWatch> ep_watch_;
			std::shared_ptr<Channel> channel_;
			NewConnectCb new_conn_cb_;
		};




	}
}
